#ifndef lint
static const char yysccsid[] = "@(#)yaccpar	1.9 (Berkeley) 02/21/93";
#endif

#include <stdlib.h>
#include <string.h>

#define YYBYACC 1
#define YYMAJOR 1
#define YYMINOR 9
#define YYPATCH 20070509

#define YYEMPTY (-1)
#define yyclearin    (yychar = YYEMPTY)
#define yyerrok      (yyerrflag = 0)
#define YYRECOVERING (yyerrflag != 0)

extern int yyparse(void);

static int yygrowstack(void);
#define YYPREFIX "yy"
#line 2 "dtd1.y"
#include <stdio.h>
#include <malloc.h>		/* added by NPM */
/* #define DEBUG */
/* NPM: removed this extern char *calloc(); */

/*
 * Read the information at the beginning of dtd1.l for
 * more information about this program.
 */

/*
 * Structure used to create a linked list of entities including
 * their key and data.
 */
static struct entityDef {
    char *key;
    char *data;
    struct entityDef *next;		/* For table insertion */
    struct entityDef *prev;		/* For table insertion */
} *topEntList, *bottomEntList, *saveEntList;

/*
 * Structure used to create a linked list of the SGML markups
 * found in the dtd.  Currently only ENTITY and ATTLIST are supported.
 */
static struct SGMLitem {
    char *str;		/* Will change to include ENTITY and ATTLIST later */
    struct SGMLitem *next;
    struct SGMLitem *prev;		/* For table insertion */
} *topSGMLList, *bottomSGMLList, *saveSGMLList;

extern int yygetlineno();
void yyerror(char *s);

static void addEntTable(struct entityDef *new);
static char *LookupEnt(char *key);
static struct entityDef *newEntity(char *key, char *data);
static void DumpEntTable();
static void FreeEntTable();

static void addSGMLTable(struct SGMLitem *new);
static struct SGMLitem *newSGML(char *string);
static void DumpSGMLTable();

#define SGMLTYPE	1
#define ENTDEFTYPE	2
#line 50 "dtd1.y"
typedef union {
    char *string;
    int option;
    struct entityDef *entitydef;
    struct SGMLitem *sgmlitem;
    int sgmltype;		/* SGMLTYPE or ENTDEFTYPE */
} YYSTYPE;
#line 78 "y.tab.c"
#define SGML 257
#define COND 258
#define ENTSTART 259
#define QUOTE 260
#define ELESTART 261
#define ATTSTART 262
#define WORD 263
#define ENTITY 264
#define COMMENTEND 265
#define YYERRCODE 256
short yylhs[] = {                                        -1,
    0,    0,    0,   10,   10,    5,    5,    9,    9,    9,
    8,    8,    8,    8,    8,    4,    4,    6,    6,   12,
   12,    1,    1,    3,    3,   11,    7,    7,    7,    7,
    7,    7,    7,    7,    7,    2,    2,    2,    2,
};
short yylen[] = {                                         2,
    1,    2,    1,    1,    1,    1,    2,    1,    1,    1,
    3,    3,    2,    4,    3,    1,    2,    1,    1,    1,
    1,    1,    2,    1,    1,    7,    5,    5,    5,    4,
    3,    6,    6,    5,    5,    3,    2,    3,    2,
};
short yydefred[] = {                                      0,
    3,    0,    0,    0,    0,    0,   10,    0,    0,    9,
    8,    6,    1,    5,    0,   21,   20,   13,   24,   25,
    0,    0,    0,    0,    0,   19,   22,    0,   16,    0,
    2,    7,   15,    0,    0,    0,   31,    0,   39,   37,
    0,   23,   17,   11,   12,   14,    0,    0,   30,    0,
    0,   38,   36,    0,   35,   34,    0,   29,   28,   27,
    0,   33,   32,   26,
};
short yydgoto[] = {                                       8,
   25,   26,   27,   28,    9,   29,   10,   11,   12,   13,
   14,   18,
};
short yysindex[] = {                                   -227,
    0,  -57, -244,  -37, -191, -191,    0, -200, -194,    0,
    0,    0,    0,    0, -238,    0,    0,    0,    0,    0,
  -64, -230, -247, -218, -244,    0,    0,  -60,    0,  -60,
    0,    0,    0,  -60, -194, -221,    0, -220,    0,    0,
 -208,    0,    0,    0,    0,    0,  -90,  -55,    0, -221,
  -58,    0,    0,  -52,    0,    0,  -54,    0,    0,    0,
  -12,    0,    0,    0,
};
short yyrindex[] = {                                      0,
    0,    0,    0,    0,    0,    0,    0,    0,    1,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,  -51,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,
};
short yygindex[] = {                                      0,
   30,  -26,    3,    8,   25,  -13,    0,    0,    4,   58,
    0,   19,
};
#define YYTABLESIZE 259
short yytable[] = {                                      23,
    4,   17,   54,   60,   17,   21,   56,   63,   37,   48,
   18,   51,   32,   30,   43,   38,   43,   33,   19,   20,
   43,   24,   34,   57,   19,   20,   35,   42,    1,    2,
    3,    4,   36,    5,    6,   49,    7,   39,   24,   24,
   61,   40,   50,   42,   19,   20,   44,   52,   45,   64,
   32,   53,   46,   41,   19,   20,    2,    3,    4,   47,
    5,    6,    2,    7,    4,   31,    5,    6,   24,    7,
    0,   19,   20,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    2,    0,    4,    0,
    5,    6,    0,    7,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,   58,    0,   24,
    0,    0,   19,   20,   16,   15,   59,   16,   18,   55,
   62,    0,    0,   18,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,   22,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    4,
};
short yycheck[] = {                                      37,
    0,   62,   93,   62,   62,    3,   62,   62,  256,   36,
   62,   38,    9,    6,   28,  263,   30,  256,  263,  264,
   34,  260,   15,   50,  263,  264,   91,   25,  256,  257,
  258,  259,  263,  261,  262,  256,  264,  256,  260,  260,
   93,  260,  263,   41,  263,  264,   28,  256,   30,   62,
   47,  260,   34,   24,  263,  264,  257,  258,  259,   35,
  261,  262,  257,  264,  259,    8,  261,  262,  260,  264,
   -1,  263,  264,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,  257,   -1,  259,   -1,
  261,  262,   -1,  264,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,  256,   -1,  260,
   -1,   -1,  263,  264,  265,  263,  265,  265,  260,  265,
  265,   -1,   -1,  265,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,  263,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  258,
};
#define YYFINAL 8
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 265
#if YYDEBUG
char *yyname[] = {
"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,"'%'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'>'",0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'['",0,"']'",0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"SGML","COND",
"ENTSTART","QUOTE","ELESTART","ATTSTART","WORD","ENTITY","COMMENTEND",
};
char *yyrule[] = {
"$accept : top",
"top : line",
"top : top line",
"top : error",
"line : sgmllist",
"line : cond",
"sgmllist : sgmllistitem",
"sgmllist : sgmllist sgmllistitem",
"sgmllistitem : sgml",
"sgmllistitem : entdef",
"sgmllistitem : ENTITY",
"sgml : ELESTART sgmlcontent sgmlend",
"sgml : ATTSTART sgmlcontent sgmlend",
"sgml : SGML sgmlend",
"sgml : SGML WORD sgmlcontent sgmlend",
"sgml : SGML WORD error",
"sgmlcontent : sgmlcontentitem",
"sgmlcontent : sgmlcontent sgmlcontentitem",
"sgmlcontentitem : words",
"sgmlcontentitem : qstring",
"sgmlend : '>'",
"sgmlend : COMMENTEND",
"words : word",
"words : words word",
"word : WORD",
"word : ENTITY",
"cond : COND word '[' sgmllist ']' ']' '>'",
"entdef : ENTSTART '%' WORD qstring '>'",
"entdef : ENTSTART '%' WORD qstring COMMENTEND",
"entdef : ENTSTART '%' WORD qstring error",
"entdef : ENTSTART '%' WORD error",
"entdef : ENTSTART '%' error",
"entdef : ENTSTART '%' WORD WORD qstring '>'",
"entdef : ENTSTART '%' WORD WORD qstring COMMENTEND",
"entdef : ENTSTART WORD WORD qstring '>'",
"entdef : ENTSTART WORD WORD qstring COMMENTEND",
"qstring : QUOTE words QUOTE",
"qstring : QUOTE QUOTE",
"qstring : QUOTE words error",
"qstring : QUOTE error",
};
#endif
#if YYDEBUG
#include <stdio.h>
#endif

/* define the initial stack-sizes */
#ifdef YYSTACKSIZE
#undef YYMAXDEPTH
#define YYMAXDEPTH  YYSTACKSIZE
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 500
#define YYMAXDEPTH  500
#endif
#endif

#define YYINITSTACKSIZE 500

int      yydebug;
int      yynerrs;
int      yyerrflag;
int      yychar;
short   *yyssp;
YYSTYPE *yyvsp;
YYSTYPE  yyval;
YYSTYPE  yylval;

/* variables for the parser stack */
static short   *yyss;
static short   *yysslim;
static YYSTYPE *yyvs;
static int      yystacksize;
#line 391 "dtd1.y"

extern FILE *yyin;

main()
{
    while (!feof(yyin)) {
	yyparse();
    }
    /*
    DumpEntTable();
    */

    /*
     * DumpSGMLTable() writes out the SGML table which is
     * now cleaned up and processed.
     */
    DumpSGMLTable();
    FreeEntTable();
    exit(0);
}

void
yyerror(char *s)
{
    fprintf(stderr, "%d: %s\n", yygetlineno(), s);
}


/***************** Entities ******************/


/*
 * Add a new entity to the entity list.
 */
static void
addEntTable(struct entityDef *new)
{
    /* Only first reference gets added to the table */
    char *cp = LookupEnt(new->key);
    if (cp == NULL) {
	if (topEntList == 0) {
	    topEntList = new;
	    bottomEntList = new;
	}
	else {
	    bottomEntList->next = new;
	    new->prev = bottomEntList;
	    bottomEntList = new;
	}
    }
    else {

#ifdef DEBUG
	fprintf(stderr, "\tIgnoring New Entity %s: %s\n",
		new->key,
		new->data);
#endif /* DEBUG */

	free(new->key);
	free(new->data);
	free(new);
    }
}

/*
 * Lookup an entity in the entity list.
 * To avoid memory and freeing problems, we save the value
 * with the existing quote at the beginning.  We have to
 * avoid it when we return the entity value.
 */
static char *
LookupEnt(char *key)
{
    struct entityDef *cur = topEntList;
    while (cur) {
	if (strcmp(cur->key, key) == 0)
	    return (cur->data + 1);		/* Skip first " */
	cur = cur->next;
    }
    return (NULL);
}

/*
 * Create a new entity.
 */
static struct entityDef *
newEntity(char *key, char *data)
{
    struct entityDef *new = (struct entityDef *)malloc(sizeof(struct entityDef));

    new->key = key;
    new->data = data;
    new->next = 0;
    data[strlen(data) - 1] = 0;		/* Nuke last " */
    /*
    fprintf(stderr, "Creating entity: %s = %s\n", key, data);
    */
    return (new);
}

/*
 * Print out the entity table.  This is used only for debugging.
 */
static void
DumpEntTable()
{
    struct entityDef *cur = topEntList;
    fprintf(stderr, "\nEntity Table (0x%x):\n", topEntList);
    while (cur) {
	fprintf(stderr, "%%%s : %s\n", cur->key, cur->data + 1);
	cur = cur->next;
    }
}

/*
 * Clean up the entity table.
 */
static void
FreeEntTable()
{
    struct entityDef *cur = topEntList;
    while (cur) {
	struct entityDef *save = cur->next;
	
	free(cur->key);
	free(cur->data);
	free(cur);
	cur = save;
    }
    topEntList = 0;
}

/***************** SGML ******************/

/*
 * Add a new SGML markup to the SGML list.
 */
static void
addSGMLTable(struct SGMLitem *new)
{
    if (topSGMLList == 0) {
	topSGMLList = new;
	bottomSGMLList = new;
    }
    else {
	bottomSGMLList->next = new;
	new->prev = bottomSGMLList;
	bottomSGMLList = new;
    }
}

/*
 * Create a new data structure for the SGML markup.
 */
static struct SGMLitem *
newSGML(char *string)
{
    struct SGMLitem *new = (struct SGMLitem *)malloc(sizeof(struct SGMLitem));

    new->str = string;
    new->next = 0;
    /*
    fprintf(stderr, "Creating SGML: %s\n", string);
    */
    return (new);
}

/*
 * Write out the SGML table.  Note that the strings in the SGML
 * list are of the standard form:
 *	<blah foo1 foo2 ... >
 * so they can be written out directly.
 */
static void
DumpSGMLTable()
{
    struct SGMLitem *cur = topSGMLList;

    while (cur) {
	fprintf(stdout, "%s\n", cur->str);
	cur = cur->next;
    }
}

#line 470 "y.tab.c"
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
static int yygrowstack(void)
{
    int newsize, i;
    short *newss;
    YYSTYPE *newvs;

    if ((newsize = yystacksize) == 0)
        newsize = YYINITSTACKSIZE;
    else if (newsize >= YYMAXDEPTH)
        return -1;
    else if ((newsize *= 2) > YYMAXDEPTH)
        newsize = YYMAXDEPTH;

    i = yyssp - yyss;
    newss = (yyss != 0)
          ? (short *)realloc(yyss, newsize * sizeof(*newss))
          : (short *)malloc(newsize * sizeof(*newss));
    if (newss == 0)
        return -1;

    yyss  = newss;
    yyssp = newss + i;
    newvs = (yyvs != 0)
          ? (YYSTYPE *)realloc(yyvs, newsize * sizeof(*newvs))
          : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
    if (newvs == 0)
        return -1;

    yyvs = newvs;
    yyvsp = newvs + i;
    yystacksize = newsize;
    yysslim = yyss + newsize - 1;
    return 0;
}

#define YYABORT goto yyabort
#define YYREJECT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
yyparse(void)
{
    register int yym, yyn, yystate;
#if YYDEBUG
    register const char *yys;

    if ((yys = getenv("YYDEBUG")) != 0)
    {
        yyn = *yys;
        if (yyn >= '0' && yyn <= '9')
            yydebug = yyn - '0';
    }
#endif

    yynerrs = 0;
    yyerrflag = 0;
    yychar = YYEMPTY;

    if (yyss == NULL && yygrowstack()) goto yyoverflow;
    yyssp = yyss;
    yyvsp = yyvs;
    *yyssp = yystate = 0;

yyloop:
    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
    if (yychar < 0)
    {
        if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
        if (yydebug)
        {
            yys = 0;
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
            if (!yys) yys = "illegal-symbol";
            printf("%sdebug: state %d, reading %d (%s)\n",
                    YYPREFIX, yystate, yychar, yys);
        }
#endif
    }
    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
    {
#if YYDEBUG
        if (yydebug)
            printf("%sdebug: state %d, shifting to state %d\n",
                    YYPREFIX, yystate, yytable[yyn]);
#endif
        if (yyssp >= yysslim && yygrowstack())
        {
            goto yyoverflow;
        }
        *++yyssp = yystate = yytable[yyn];
        *++yyvsp = yylval;
        yychar = YYEMPTY;
        if (yyerrflag > 0)  --yyerrflag;
        goto yyloop;
    }
    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
    {
        yyn = yytable[yyn];
        goto yyreduce;
    }
    if (yyerrflag) goto yyinrecovery;

    yyerror("syntax error");

#ifdef lint
    goto yyerrlab;
#endif

yyerrlab:
    ++yynerrs;

yyinrecovery:
    if (yyerrflag < 3)
    {
        yyerrflag = 3;
        for (;;)
        {
            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
            {
#if YYDEBUG
                if (yydebug)
                    printf("%sdebug: state %d, error recovery shifting\
 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
#endif
                if (yyssp >= yysslim && yygrowstack())
                {
                    goto yyoverflow;
                }
                *++yyssp = yystate = yytable[yyn];
                *++yyvsp = yylval;
                goto yyloop;
            }
            else
            {
#if YYDEBUG
                if (yydebug)
                    printf("%sdebug: error recovery discarding state %d\n",
                            YYPREFIX, *yyssp);
#endif
                if (yyssp <= yyss) goto yyabort;
                --yyssp;
                --yyvsp;
            }
        }
    }
    else
    {
        if (yychar == 0) goto yyabort;
#if YYDEBUG
        if (yydebug)
        {
            yys = 0;
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
            if (!yys) yys = "illegal-symbol";
            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
                    YYPREFIX, yystate, yychar, yys);
        }
#endif
        yychar = YYEMPTY;
        goto yyloop;
    }

yyreduce:
#if YYDEBUG
    if (yydebug)
        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
                YYPREFIX, yystate, yyn, yyrule[yyn]);
#endif
    yym = yylen[yyn];
    if (yym)
        yyval = yyvsp[1-yym];
    else
        memset(&yyval, 0, sizeof yyval);
    switch (yyn)
    {
case 1:
#line 69 "dtd1.y"
{
		    }
break;
case 2:
#line 72 "dtd1.y"
{
		    }
break;
case 3:
#line 75 "dtd1.y"
{
			fprintf(stderr, "%d: syntax error\n", yygetlineno());
		    }
break;
case 6:
#line 84 "dtd1.y"
{
			/*
			 * First item in the list.
			 * We need to save the state of the entity table
			 * and the SGML list so we can back out our changes
			 * if we are in a conditional and it proves to be
			 * an IGNORE. This global hack does limit us to one
			 * level of depth on conditional SGMLs.
			 *
			 * Note that by now the first Entity or SGML 
			 * has been added to the list, so we have to
			 * use the previous when we save the state of that
			 * list.
			 */
			if (bottomEntList) {
			    if (yyvsp[0].sgmltype == ENTDEFTYPE)
				saveEntList = bottomEntList->prev;
			    else
				saveEntList = bottomEntList;
			}
			if (bottomSGMLList) {
			    if (yyvsp[0].sgmltype == SGMLTYPE)
				saveSGMLList = bottomSGMLList->prev;
			    else
				saveSGMLList = bottomSGMLList;
			}
		    }
break;
case 8:
#line 116 "dtd1.y"
{
			/*
			 * We have a complete SGML statement.
			 * Save it in the SGML list (table).
			 */
			if (yyvsp[0].sgmlitem) {
#ifdef DEBUG
			    fprintf(stderr, "New SGML %s\n",
				    yyvsp[0].sgmlitem->str);
#endif
			    addSGMLTable(yyvsp[0].sgmlitem);
			}
			yyval.sgmltype = SGMLTYPE;
		    }
break;
case 9:
#line 131 "dtd1.y"
{
			/*
			 * We have defined an entity.
			 * Save it in the Entity list (table).
			 */
			if (yyvsp[0].entitydef) {
#ifdef DEBUG
			    fprintf(stderr, "New Entity %s: %s\n",
				    yyvsp[0].entitydef->key,
				    yyvsp[0].entitydef->data);
#endif
			    addEntTable(yyvsp[0].entitydef);
			}
			yyval.sgmltype = ENTDEFTYPE;
		    }
break;
case 10:
#line 147 "dtd1.y"
{
			/*
			 * There are cases in the dtd where we get lines like:
			 * 		%ISOlat1;
			 * in the dtd.  We just print a warning and ignore
			 * these lines.
			 */
			fprintf(stderr, "%d: Ignoring single line entity: %s\n",
				yygetlineno(),
				yyvsp[0].string);
			yyval.sgmltype = 0;
		    }
break;
case 11:
#line 162 "dtd1.y"
{
			char *str = malloc(4096);

			sprintf(str, "<!ELEMENT %s>", yyvsp[-1].string);
			free (yyvsp[-1].string);
			yyval.sgmlitem = newSGML(str);
		    }
break;
case 12:
#line 170 "dtd1.y"
{
			char *str = malloc(4096);

			sprintf(str, "<!ATTLIST %s>", yyvsp[-1].string);
			free (yyvsp[-1].string);
			yyval.sgmlitem = newSGML(str);
		    }
break;
case 13:
#line 178 "dtd1.y"
{
			/* Empty sgml -- probably an eaten comment */
			yyval.sgmlitem = 0;
			/*
			sprintf($$, "<!-- deleted comment -->");
			*/
		    }
break;
case 14:
#line 186 "dtd1.y"
{
			char *str = malloc(4096);

			sprintf(str, "<!%s %s>", yyvsp[-2].string, yyvsp[-1].string);
			yyval.sgmlitem = newSGML(str);
			fprintf(stderr, "Unknown SGML passed through: %s\n",
				yyvsp[-2].string);
			free (yyvsp[-2].string);
			free (yyvsp[-1].string);
		    }
break;
case 15:
#line 197 "dtd1.y"
{
			fprintf(stderr, "Unknown SGML ignored: %s\n", yyvsp[-1].string);
			free(yyvsp[-1].string);
			yyval.sgmlitem = 0;
		    }
break;
case 16:
#line 205 "dtd1.y"
{
			yyval.string = yyvsp[0].string;
		    }
break;
case 17:
#line 209 "dtd1.y"
{
			strcat(yyval.string, " ");
			strcat(yyval.string, yyvsp[0].string);
			free(yyvsp[0].string);
		    }
break;
case 18:
#line 217 "dtd1.y"
{
			yyval.string = yyvsp[0].string;
		    }
break;
case 19:
#line 221 "dtd1.y"
{
			yyval.string = yyvsp[0].string;
		    }
break;
case 22:
#line 231 "dtd1.y"
{
			yyval.string = calloc(1, 4096);
			strcat(yyval.string, yyvsp[0].string);
			free(yyvsp[0].string);
			/*
			fprintf(stderr, "Starting words: %s\n", $$);
			*/
		    }
break;
case 23:
#line 240 "dtd1.y"
{
			yyval.string = yyvsp[-1].string;
			strcat(yyval.string, " ");
			strcat(yyval.string, yyvsp[0].string);
			free(yyvsp[0].string);
			/*
			fprintf(stderr, "Adding to words: %s\n", $$);
			*/
		    }
break;
case 24:
#line 252 "dtd1.y"
{
			yyval.string = yyvsp[0].string;
		    }
break;
case 25:
#line 256 "dtd1.y"
{
			char *ent = LookupEnt(yyvsp[0].string);
			if (ent == NULL) {
			    fprintf(stderr, "%d: Unknown Entity: %s\n",
				    yygetlineno(), yyvsp[0].string);
			    yyval.string = calloc(1, 1);
			}
			else {
			    yyval.string = (char *)strdup(ent);
			}
		    }
break;
case 26:
#line 270 "dtd1.y"
{
			/*
			 * We have to read in the entire list before
			 * we evaluate the conditional.  Because of
			 * this, we may have added entities and SGMLS
			 * to the those lists which we want to get
			 * rid of.  That's what happens here.
			 */
			if (strcmp(yyvsp[-5].string, "IGNORE") == 0) {
			    /* Reset the lists to ignore the contents */
			    if (saveEntList) {
				saveEntList->next = 0;	/* Lose data */
				bottomEntList = saveEntList;
			    }
			    /* else error XXX */

			    if (saveSGMLList) {
				saveSGMLList->next = 0;
				bottomSGMLList = saveSGMLList;
			    }
			    /* else error XXX */
			}
		    }
break;
case 27:
#line 296 "dtd1.y"
{
			yyval.entitydef = newEntity(yyvsp[-2].string, yyvsp[-1].string);
		    }
break;
case 28:
#line 300 "dtd1.y"
{
			yyval.entitydef = newEntity(yyvsp[-2].string, yyvsp[-1].string);
		    }
break;
case 29:
#line 304 "dtd1.y"
{
			fprintf(stderr, "%d: incomplete entity: %s\n",
				yygetlineno(),
				yyvsp[-2].string);
			free(yyvsp[-2].string);
			free(yyvsp[-1].string);
			yyval.entitydef = 0;
		    }
break;
case 30:
#line 313 "dtd1.y"
{
			fprintf(stderr, "%d: incomplete entity: %s\n",
				yygetlineno(),
				yyvsp[-1].string);
			free(yyvsp[-1].string);
			yyval.entitydef = 0;
		    }
break;
case 31:
#line 321 "dtd1.y"
{
			fprintf(stderr, "%d: incomplete entity\n",
				yygetlineno());
			yyval.entitydef = 0;
		    }
break;
case 32:
#line 327 "dtd1.y"
{
			yyval.entitydef = newEntity(yyvsp[-3].string, yyvsp[-1].string);
			free(yyvsp[-2].string);
		    }
break;
case 33:
#line 332 "dtd1.y"
{
			fprintf(stderr, "%d: Ignoring entity %s\n",
				yygetlineno(),
				yyvsp[-3].string);
			free(yyvsp[-3].string);
			free(yyvsp[-2].string);
			free(yyvsp[-1].string);
			yyval.entitydef = 0;
		    }
break;
case 34:
#line 342 "dtd1.y"
{
			fprintf(stderr, "%d: Ignoring entity %s\n",
				yygetlineno(),
				yyvsp[-2].string);
			free(yyvsp[-3].string);
			free(yyvsp[-2].string);
			free(yyvsp[-1].string);
			yyval.entitydef = 0;
		    }
break;
case 35:
#line 352 "dtd1.y"
{
			fprintf(stderr, "%d: Ignoring entity %s\n",
				yygetlineno(),
				yyvsp[-3].string);
			free(yyvsp[-3].string);
			free(yyvsp[-2].string);
			free(yyvsp[-1].string);
			yyval.entitydef = 0;
		    }
break;
case 36:
#line 364 "dtd1.y"
{
			yyval.string = calloc(1, 4096);
			sprintf(yyval.string, "\"%s\"", yyvsp[-1].string);
			free (yyvsp[-1].string);
			/*
			fprintf(stderr, "Got qstring: %s\n", $$);
			*/
		    }
break;
case 37:
#line 373 "dtd1.y"
{
			sprintf(yyval.string, "\"\"");
			/*
			fprintf(stderr, "Got qstring: %s\n", $$);
			*/
		    }
break;
case 38:
#line 380 "dtd1.y"
{
			fprintf(stderr, "%d: missing endquote\n", yygetlineno());
		    }
break;
case 39:
#line 384 "dtd1.y"
{
			fprintf(stderr, "%d: incomplete quote\n", yygetlineno());
		    }
break;
#line 1009 "y.tab.c"
    }
    yyssp -= yym;
    yystate = *yyssp;
    yyvsp -= yym;
    yym = yylhs[yyn];
    if (yystate == 0 && yym == 0)
    {
#if YYDEBUG
        if (yydebug)
            printf("%sdebug: after reduction, shifting from state 0 to\
 state %d\n", YYPREFIX, YYFINAL);
#endif
        yystate = YYFINAL;
        *++yyssp = YYFINAL;
        *++yyvsp = yyval;
        if (yychar < 0)
        {
            if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
            if (yydebug)
            {
                yys = 0;
                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
                if (!yys) yys = "illegal-symbol";
                printf("%sdebug: state %d, reading %d (%s)\n",
                        YYPREFIX, YYFINAL, yychar, yys);
            }
#endif
        }
        if (yychar == 0) goto yyaccept;
        goto yyloop;
    }
    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
        yystate = yytable[yyn];
    else
        yystate = yydgoto[yym];
#if YYDEBUG
    if (yydebug)
        printf("%sdebug: after reduction, shifting from state %d \
to state %d\n", YYPREFIX, *yyssp, yystate);
#endif
    if (yyssp >= yysslim && yygrowstack())
    {
        goto yyoverflow;
    }
    *++yyssp = yystate;
    *++yyvsp = yyval;
    goto yyloop;

yyoverflow:
    yyerror("yacc stack overflow");

yyabort:
    return (1);

yyaccept:
    return (0);
}
